package com.sens.orderback.ui.activity;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

import com.sens.adapter.base.BaseFragmentAdapter;
import com.sens.common.ApplicationUtil;
import com.sens.common.DeviceUtil;
import com.sens.commonui.PermissionUtil;
import com.sens.orderback.R;
import com.sens.orderback.ui.activity.alipay.AlipayFragment;
import com.sens.orderback.ui.activity.mybank.MybankFragment;

public class MainActivity extends FragmentActivity {
    private AlipayFragment alipayFragment;
//    private MybankFragment mybankFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        if (!PermissionUtil.checkPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            PermissionUtil.requestPermissions(this, new PermissionUtil.OnPermissionCallback() {
                @Override
                public void onGranted() {
                }
            }, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
        }
        DeviceUtil.getDeviceId(this, new DeviceUtil.OnDeviceIdCallback() {
            @Override
            protected void onDeviceIdCallback(String deviceId) {
            }
        });

        BaseFragmentAdapter adapter = new BaseFragmentAdapter(getSupportFragmentManager());
        alipayFragment = new AlipayFragment();
        adapter.addData(alipayFragment);
//        mybankFragment = new MybankFragment();
//        adapter.addData(mybankFragment);
        ((ViewPager) findViewById(R.id.viewPager)).setAdapter(adapter);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        ApplicationUtil.moToBackground(this);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        alipayFragment.onActivityResult(requestCode, resultCode, data);
//        mybankFragment.onActivityResult(requestCode, resultCode, data);
    }
}